<?php

class Operator_model extends MY_Model
{
    protected $_table = 'chatoperator';   
    protected $primary_key = 'operatorid';   
    
    function operator_by_login($login)
    {
    	return $this->get_by_array(array('vclogin' => $login));
    }
    function operator_by_id($user_id)
    {
    	return $this->get_array($user_id);
    }
    /*function check_login($redirect = true)
    {
    	$operator = $this->get_by_array(array('vclogin' => 'admin'));
    	return $operator;
//     	$_SESSION["operator"] = $operator;
    	$operator = $this->ci->session->userdata('operator');
		 if (!isset($operator)) {
			if (isset($_COOKIE['365bustour_operator'])) {
				list($login, $pwd) = preg_split("/,/", $_COOKIE['365bustour_operator'], 2);
				$op = $this->operator_by_login($login);
				if ($op && isset($pwd) && isset($op['vcpassword']) && md5($op['vcpassword']) == $pwd) {
					$this->ci->session->set_userdata(array("operator" => $op));
					return $op;
				}
			}
			return null;
		} 
		return $operator;
    }*/
    function operator_get_all()
    {
    	$this->db->select("operatorid, vclogin, vclocalename, vccommonname, istatus, (unix_timestamp(CURRENT_TIMESTAMP)-unix_timestamp(dtmlastvisited)) as time");
    	return $this->db->get($this->_table)->result_array();
    }
}
